<template>
  <div class="topic">
    <ul>
      <li v-for="item in dataArr" :key="item.id">
        <img v-lazy="item.scene_pic_url" alt="" />
        <h3>{{ item.title }}</h3>
        <p>{{ item.subtitle }}</p>
        <p>{{ item.price_info | formatMoney }}</p>
      </li>
    </ul>
    <!-- 分页 -->
    <van-pagination
      v-model="page"
      :page-count="pageCount"
      mode="simple"
      @change="changePage"
    />
  </div>
</template>

<script>
import { getTopicApi } from "@/utils/http";
export default {
  name: "Topic",
  data() {
    return {
      page: 1, //默认的当前页
      size: 10, //默认的每页的数据条数
      dataArr: [], //页面当前数据,赋值
      pageCount: 0,
    };
  },
  created(){
    // 初始化请求数据
    this.getData()
  },
  methods: {
    // 页面请求数据
    changePage() {
      console.log(this.page); //输出当前页
      // 重新请求数据
      this.getData()
    },
    getData() {
      getTopicApi({
        // 传参
        page: this.page,
        size: this.size,
      }).then((res) => {
        // console.log(res);
        const { data, currentPage, totalPages } = res.data.data;
        this.dataArr = data;
        this.page = currentPage;
        this.pageCount = totalPages;
        // 返回顶部
        document.documentElement.scrollTop = 0;
      });
    },
  },
  
};
</script>

<style lang='less' scoped>
.topic {
  text-align: center;
  padding-bottom: 80px;
  ul {
    li {
      img {
        display: block;
        width: 100%;
      }
      h3 {
        margin-top: 20px;
        margin-bottom: 20px;
      }
      p {
        font-size: 16px;
        // margin-bottom: 15px;
        line-height: 30px;
      }
    }
  }
}
// 定义vant 组件 
// 修改ui 组件库的样式, 前缀加入 /deep/
/deep/.van-pagination__page-desc{
  display: none;
}
</style>